package com.myc.train.common.context;

import com.myc.train.common.resp.MemberLoginResp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//线程本地变量类，存储会员信息
public class LoginMemberContext {

    private static final Logger LOG = LoggerFactory.getLogger(LoginMemberContext.class);

    //定义一个线程本地变量
    private static ThreadLocal<MemberLoginResp> member =  new ThreadLocal<>();

    public static MemberLoginResp getMember() {
        return member.get();
    }

    public static void setMember(MemberLoginResp member) {
        LoginMemberContext.member.set(member);
    }

    public static Long getId(){
        try {
            return member.get().getId();
        }catch (Exception e){
            LOG.error("获取会员信息异常",e);
            throw e;
        }

    }
}
